package com.example.micrdataservice.controller;

import com.example.micrapi.pojo.SysMenu;
import com.example.micrdataservice.mapper.SysMenuMapper;
import com.example.micrdataservice.mapper.SysUserMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @description: TODO
 * @author: uu
 * @date: 2024/2/29 0:02
 * @version: 1.0
 */
@Tag(name="用户菜单")
@RequestMapping("/dataservice/sysMenu")
@RestController
@Slf4j
public class SysMenuController {
    @Autowired
    private SysMenuMapper sysMenuMapper;

    @Operation(summary = "查找用户菜单", description = "根据用户的id查询用户菜单")
    @GetMapping("/findByRoleIds")
    List<SysMenu> findByRoleIds(@RequestParam("roleIds") List<Integer> roleIds) {
        log.info("roleIds = {}", roleIds);
        List<SysMenu> menus = sysMenuMapper.selectByRoleIds(roleIds);
        return menus;
    }

    @GetMapping("/findAll")
    Page<SysMenu> findAllMenu() {
        PageHelper.startPage(1,3, "id desc");
        List<SysMenu> menus = sysMenuMapper.selectAll();
        System.out.println("menus = " + menus);
        Page<SysMenu> sysMenuPage = (Page<SysMenu>) menus;
        System.out.println("sysMenuPage = " + sysMenuPage);
        PageInfo<SysMenu> sysMenuPageInfo = new PageInfo<>(menus);
        System.out.println("sysMenuPageInfo = " + sysMenuPageInfo);
        return sysMenuPage;
    }

}
